package dao

import (
	"amin-ease/globals"
	"amin-ease/internal/dto"
	"amin-ease/internal/models"
)

type UserDao struct {
}

func NewUserDao() *UserDao {
	return &UserDao{}
}
func (u *UserDao) FindByUsername(req dto.RegisterReq) (users models.User, err error) {
	db := globals.DB
	err = db.Debug().Where("username=?", req.Username).First(&users).Error
	return users, err
}
func (u *UserDao) Register(user *models.User) (*models.User, error) {
	db := globals.DB
	err := db.Debug().Create(&user).Error
	return user, err
}
func (u *UserDao) UserList(req dto.ListReq) (users []models.User, err error) {
	offset := (req.Page - 1) * req.Size
	db := globals.DB
	err = db.Debug().Offset(offset).Limit(req.Size).Find(&users).Error
	return users, err
}
func (u *UserDao) FindUser(req dto.UsersReq) (user models.UserPerson, err error) {
	db := globals.DB
	err = db.Debug().Where("user_id=?", req.UserId).Find(&user).Error
	return user, err
}
func (u *UserDao) Add(person *models.Ping) (*models.Ping, error) {
	db := globals.DB
	err := db.Debug().Create(&person).Error
	return person, err
}
